package groupb6.shopsystem.controller.customer;

import com.alibaba.druid.sql.PagerUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import groupb6.shopsystem.pojo.entity.Product;
import groupb6.shopsystem.pojo.template.PageInfo;
import groupb6.shopsystem.service.CustomerHomepageService;
import groupb6.shopsystem.util.response.UniversalResponse;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "10:顾客主页")
@ApiSupport(author = "zhangyn")
@RestController
@RequestMapping("/customer/home")
public class CustomerHomepageController {
    @Autowired
    private CustomerHomepageService customerHomepageService;


    @ApiOperation("分页查询商品")
    @GetMapping("/page")
    @ApiResponses(value = {
            @ApiResponse(code = 1000, message = "成功"),
            @ApiResponse(code = 1001, message = "错误"),})
    @ResponseBody
    public UniversalResponse<PageInfo<Product>> page(@RequestParam(defaultValue = "") String keyword,
                                   @RequestParam(defaultValue = "1") Integer pageNum,
                                   @RequestParam(defaultValue = "12")Integer pageSize) {

        Page<Product> page=new Page<>(pageNum,pageSize);
        try{
            PageInfo pageInfo = customerHomepageService.findProductsByPage(page, keyword);
            return new UniversalResponse<>(1000, "成功", pageInfo);
        }catch (RuntimeException e){
            return new UniversalResponse<>(1001,e.getMessage());
        }
    }

//    @ApiOperation("条件筛选查询商品")
//    @GetMapping("/filter")
//    @ApiResponses(value = {
//            @ApiResponse(code = 200, message = "成功"),
//            @ApiResponse(code = 500, message = "错误"),})
//    @ResponseBody
//    public UniversalResponse filter(@RequestParam(defaultValue = "") CustomerProductFilterForm filter,
//                                  @RequestParam(defaultValue = "1") Integer pageNum,
//                                  @RequestParam(defaultValue = "12")Integer pageSize) {
//
//        Page<Product> page=new Page<>(pageNum,pageSize);
//        try{
//            PageInfo pageInfo = customerHomepageService.findProductsByFilter(page, filter);
//            return new UniversalResponse<>(200, "成功", pageInfo);
//        }catch (RuntimeException e){
//            return new UniversalResponse<>(500,e.getMessage());
//        }
//    }
}
